﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class ActiveUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string usernameCanActive = Request.QueryString["username"].ToString();
        string randomKey = Request.QueryString["randomkey"].ToString();
        string strSQL = "SELECT active FROM users WHERE username=@username";
        SqlParameter param = new SqlParameter("@username", usernameCanActive);
        DataTable dt = DBClass.SelectData(strSQL, param);
        if(dt.Rows[0]["Active"].ToString() == "1")
        {
            _lbl1.Visible = false;
            _lbl2.Visible = false;
            _lbl3.Visible = false;
            _lbl4.Text = "Tài khoản đã được kích hoạt rồi";
        }
        else
        {
            string active = "1";
            strSQL = "UPDATE users SET active=@active WHERE username=@username AND RandomKey=@RandomKey";
            SqlParameter[] parameters = {
                                            new SqlParameter("@Active", active), 
                                            new SqlParameter("@Username", usernameCanActive), 
                                            new SqlParameter("@RandomKey", randomKey)
            };
            int nor = DBClass.Execute(strSQL, parameters);
            _lbl1.Visible = true;
            _lbl2.Visible = true;
            _lbl3.Visible = true;
            _lbl4.Visible = false;
        }
    }
}
